#!/usr/bin/python
#coding: utf-8
"""
@Name:01_nmap端口扫描.py
@Data:20-5-3
@Author:181
"""

import  nmap

def get_active_hosts(hosts='172.25.135.13',ports='22,80'):
    nm = nmap.PortScanner()
    # 以指定方式扫描指定主机或网段的指定端口
    #result = nm.scan(hosts='172.25.135.0/24', arguments='-n -sP')
    result = nm.scan(hosts=hosts, ports=ports,arguments='-n ')
    print("扫描结果: ", result)
    # 返回nmap扫描的主机清单,格式为列表类型
    print("主机清单: ", nm.all_hosts())
if __name__ == '__main__':
    active_hosts = get_active_hosts()
    print("所有存活的主机: ", active_hosts)